﻿using System;
using Newtonsoft.Json;
namespace Zeus.Mvc
{
    using Results;
    using Loggers;
    public class ZeusMvcOptions
    {
        private const string _defaultDateFormatString = "yyyy-MM-dd HH:mm:ss";

        public bool EnableZeusReuslt {
            get; set;
        }

        public Type TypeOfIZeusResultExecutor {
            get;
        }

        public Type TypeOfIZeusResultFormatter {
            get;
        }

        public Type TypeOfIHttpContextLogger {
            get;
        }

        public bool EnableLogger {
            get; set;
        }

        public JsonSerializerSettings JsonSerializerSettings {
            get; set;
        }

        public bool EnableCorrilationId {
            get; set;
        }

        public ZeusMvcOptions()
        {
            EnableZeusReuslt = true;
            EnableLogger = true;
            EnableCorrilationId = true;
        }

        public ZeusMvcOptions(Type httpContextLogger) : this(null, null, httpContextLogger)
        {

        }

        public ZeusMvcOptions(Type zeusResultExecutor, Type zeusResultFormatter, Type httpContextLogger, JsonSerializerSettings jsonSerializerSettings = null) : this()
        {
            if (zeusResultExecutor != null && !typeof(IZeusResultFormatter).IsAssignableFrom(zeusResultFormatter))
            {
                throw new ArgumentException($"IZeusResultFormatter implementation error");
            }
            if (zeusResultFormatter != null && !typeof(IZeusResultFormatter).IsAssignableFrom(zeusResultFormatter))
            {
                throw new ArgumentException($"IZeusResultData implementation error");
            }
            if (httpContextLogger != null && !typeof(IHttpContextLogger).IsAssignableFrom(httpContextLogger))
            {
                throw new ArgumentException($"IHttpContextLogger implementation error");
            }
            TypeOfIZeusResultExecutor = zeusResultExecutor;
            TypeOfIZeusResultFormatter = zeusResultFormatter;
            TypeOfIHttpContextLogger = httpContextLogger;
            JsonSerializerSettings = jsonSerializerSettings ?? new JsonSerializerSettings()
            {
                DateFormatString = _defaultDateFormatString
            };
        }
    }
}
